package com.example.module_mine.ui

import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.GridLayoutManager
import com.alibaba.android.arouter.launcher.ARouter
import com.example.lib_common.base.BaseFragment
import com.example.module_mine.R
import com.example.module_mine.databinding.FragmentMineBinding
import com.example.module_mine.login.loginnet.MineModel
import com.example.module_mine.ui.adapter.MineAdapter
import com.tencent.mmkv.MMKV
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MineFragment : BaseFragment<MineViewModel, FragmentMineBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.fragment_mine

    private val mviewmodel: MineViewModel by viewModels()
    lateinit var mineAdapter: MineAdapter
    override fun initData() {
        super.initData()
        mBinding.ivMine.setOnClickListener {
            ARouter.getInstance().build("/login/login").navigation()
        }
    }

    override fun initView() {
        super.initView()
        mineAdapter = MineAdapter()
        mBinding.rv.adapter = mineAdapter
        mineAdapter.setData(mviewmodel.getlist() as MutableList<MineModel>)
        mBinding.rv.layoutManager = GridLayoutManager(context, 4)


        //
        var s = MMKV.defaultMMKV().decodeString("username")
//        Toast.makeText(requireContext(), ""+s, Toast.LENGTH_SHORT).show()
        if (s != null) {
            if (s.isNotEmpty()) {
                mBinding.usernameMine.text = MMKV.defaultMMKV().decodeString("username")
                mineAdapter.setData(mviewmodel.getlist2() as MutableList<MineModel>)
            }
        } else {
            ARouter.getInstance().build("/login/login").navigation()
        }

//
        //更新
    }

    override fun initListener() {
        super.initListener()
    }

}